package com.heima.admin.controller;

import com.heima.admin.entity.AdChannel;
import com.heima.admin.service.AdChannelService;
import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.admin.dtos.ChannelQueryDTO;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ChannelController {

    @Autowired
    private AdChannelService channelService;

    /**
     * 分页查询频道列表信息
     * */
    @PostMapping("/api/v1/channel/list")
    public PageResult<AdChannel> list(@RequestBody ChannelQueryDTO dto,
                                      @RequestHeader(value = "userId", defaultValue = "-1") Integer userId){
        log.info("ChannelController, userId={}", userId);
        return channelService.findByPage(dto);
    }

    @GetMapping("/api/v1/channel/channels")
    public ResponseResult<List<AdChannel>> channel(){
        List<AdChannel> list = channelService.list();
        return ResponseResult.ok(list);
    }

}
